package com.leetcode.sort;


/**
 * 合并两个有序数组
 */
public class Solution88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        if (nums1 == null || nums2 == null || nums1.length != m + n) {
            return;
        }

        int point1 = 0;
        int point2 = 0;
        while (point1 < m && point2 < n) {
            if (nums1[point1] <= nums2[point2]) {
                point1++;
            } else {
                int tmp = m;
                while (tmp > point1) {
                    nums1[tmp] = nums1[tmp-1];
                    tmp--;
                }
                nums1[point1] = nums2[point2];
                m++;
                point1++;
                point2++;
            }
        }

        while (point2 < n) {
            nums1[point1++] = nums2[point2++];
        }
    }
}
